/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.panel;

import org.rails.extjs.Option;
import org.rails.extjs.javascript.Function;

public class Window extends Panel {
	
	public static final String CLOSE_ACTION_CLOSE = "close";
	public static final String CLOSE_ACTION_HIDE = "hide";

	public Window() {
		super();
	}

	public Window(Option configOptions) {
		super(configOptions);
	}

	public Window(String title) {
		super(title);
	}

	public Window(String id, String title) {
		super(id, title);
	}
	
	public void setAnimateTarget(Object animateTarget){
		addOption("animateTarget",animateTarget);
	}
	
	public Object getAnimateTarget(){
		return getOption("animateTarget");
	}
	
	public String getBaseClassName(){
		return getString("baseCls","x-window");
	}
	
	public void setCloseAction(String closeAction){
		addOption("closeAction",closeAction);
	}
	
	public String getCloseAction(){
		return getString("closeAction",CLOSE_ACTION_CLOSE);
	}
	
	public void setConstrain(Boolean constrain){
		addOption("constrain",constrain);
	}
	
	public Boolean isConstrain(){
		return getBoolean("constrain",false);
	}
	
	public void setConstrainHeader(Boolean constrainHeader){
		addOption("constrainHeader",constrainHeader);
	}
	
	public Boolean isConstrainHeader(){
		return getBoolean("constrainHeader",false);
	}
	
	public void setDraggable(Boolean draggable){
		addOption("draggable",draggable);
	}
	
	public Boolean isDraggable(){
		return getBoolean("draggable",true);
	}
	
	public void setExpandOnShow(Boolean expandOnShow){
		addOption("expandOnShow",expandOnShow);
	}
	
	public Boolean isExpandOnShow(){
		return getBoolean("expandOnShow",true);
	}
	
	public void setInitHidden(Boolean initHidden){
		addOption("initHidden",initHidden);
	}
	
	public Boolean isInitHidden(){
		return getBoolean("initHidden",true);
	}
	
	public void setMaximizable(Boolean maximizable){
		addOption("maximizable",maximizable);
	}
	
	public Boolean isMaximizable(){
		return getBoolean("maximizable",false);
	}
	
	public void setMaximized(Boolean maximized){
		addOption("maximized",maximized);
	}
	
	public Boolean isMaximized(){
		return getBoolean("maximized",false);
	}
	
	public void setMinHeight(Integer minHeight){
		addOption("minHeight",minHeight);
	}
	
	public Integer getMinHeight(){
		return getInteger("minHeight",100);
	}
	
	public void setMinWidth(Integer minWidth){
		addOption("minWidth",minWidth);
	}
	
	public Integer getMinWidth(){
		return getInteger("minWidth",200);
	}
	
	public void setMinimizable(Boolean minimizable){
		addOption("minimizable",minimizable);
	}
	
	public Boolean isMinimizable(){
		return getBoolean("minimizable",false);
	}
	
	public void setModal(Boolean modal){
		addOption("modal",modal);
	}
	
	public Boolean isModal(){
		return getBoolean("modal",false);
	}
	
	public void onEsc(Function onEsc){
		addOption("onEsc",onEsc);
	}
	
	public void setPlain(Boolean plain){
		addOption("plain",plain);
	}
	
	public Boolean isPlain(){
		return getBoolean("plain",false);
	}
	
	public void setResizable(Boolean resizable){
		addOption("resizable",resizable);
	}
	
	public Boolean isResizable(){
		return getBoolean("resizable",true);
	}
	
	public void setResizeHandles(String resizeHandles){
		addOption("resizeHandles",resizeHandles);
	}
	
	public String getResizeHandles(){
		return getString("resizeHandles","all");
	}
	
	public Boolean isClosable(){
		return getBoolean("Closable",false);
	}
	
	@Override
	public String getScript() {
		script = new StringBuffer("");
		createItems();
		script.append("new Ext.Window(");
		script.append(createOptions());
		script.append(").show();");
		return script.toString();
	}
	
}
